package com.happy.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.happy.entity.CourseEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author: Wuzh
 * @Description:
 * @Date Created in 15:31 2021/1/23
 * @return
 */
@Mapper
public interface CourseMapper extends BaseMapper<CourseEntity> {


    @Select (value = "<script>select ci.id,\n" +
            "       ci.level,\n" +
            "       ci.type,\n" +
            "       ci.courseTitle,\n" +
            "       ci.categoryId,\n" +
            "       c.categoryName AS categoryName,\n" +
            "       ci.studyPerson,\n" +
            "       ci.parentId,\n" +
            "       ci.createTime,\n" +
            "       ci.changeTime,\n" +
            "       ci.isUsed, fi.fileUrl AS fileUrl\n" +
            "from course_info ci\n" +
            "         left join category_info c on c.id = ci.categoryId left join file_info fi on fi.relationId=ci.id" +
            "<where><if test='courseEntity.level != null and courseEntity.level != 0'>and ci.level=#{courseEntity.level}</if>" +
            "<if test='courseEntity.categoryId != null and courseEntity.categoryId != 0'>and ci.categoryId=#{courseEntity.categoryId}</if></where></script>")
    List<CourseEntity> queryList ( @Param ( "courseEntity" ) CourseEntity courseEntity );

}
